package demo.dao;

import java.io.*;
import java.sql.ResultSet;
import java.sql.SQLException;

import demo.dbconnection.DBConnection;
import demo.logger.LoggerHelper;

public class MemberDAO
{
	private static String id;
	private static String name;
	private static String address;
	private static String job;
	private static DBConnection DBConn;

	public MemberDAO()
	{
		DBConn = new DBConnection();
		DBConn.open();
	}

	public static void setName(String inName)
	{
		name = inName;
	}

	public static void setAddress(String inAddress)
	{
		address = inAddress;
	}

	public static void setJob(String inJob)
	{
		job = inJob;
	}

	public static boolean save()
	{
		String sql = "insert into member(name,address,job) values('" + name
				+ "','" + address + "','" + job + "');";
		DBConn.update(sql);
		return true;
	}

	public static String getMaxId()
	{
		String sql = "select MAX(id) from member;";
		ResultSet rs = DBConn.query(sql);
		try
		{
			rs.next();
			return rs.getString(1);
		} catch (SQLException e)
		{
			LoggerHelper.error("MemberDAO.getMaxid", "数据库内部错误");
			e.printStackTrace();
		}
		return null;
	}

	public static ResultSet queryIdByName(String _name)
	{
		String sql = "select id from member where name = '" + _name + "';";
		return DBConn.query(sql);
	}
}